<?php
	// set variabel dan nilainya dari form registrasi
	$fullname = $_POST['fullname'];
	$username = $_POST['username'];
	$password = $_POST['password'];
	$tgl_lahir = $_POST['tgl_lahir'];
	$email = $_POST['email'];
	$gender = $_POST['gender'];
	$kota = $_POST['kota'];
	$pp_name = $_FILES['profpic']['name'];
	
	require_once('config.php');
	
	// bikin perintah query yang akan dilakukan
	$sql = "INSERT INTO user (username, password, fullname, email, gender, kota, tgllahir, pp) VALUES ('".$username."', '".$password."','".$fullname."', '".$email."', '".$gender."', '".$kota."', '".$tgl_lahir."', '".$pp_name."')";
	$result1 = mysql_query($sql);
	
	$uploads_dir = 'resources/';
    if ($error == UPLOAD_ERR_OK) {
        $tmp_name = $_FILES['profpic']['tmp_name'];
        $name = $_FILES['profpic']['name'];
		move_uploaded_file($tmp_name, $uploads_dir.$name);
	}
	if (result1) {
		$sql="SELECT iduser FROM user WHERE username='$username' AND password='$password'";
		$result2=mysql_query($sql);
		while($activeuser = mysql_fetch_array($result2))
		{
			$res = $activeuser['iduser'];
		}
	}
	
	if (!result2) {
		die('Error : ' .mysql_error());
	}
	else{
		// Set Cookie User
		setcookie("id_active", $res);
		header("Location:".$url."home2.php");
	}
?>